<template>
	<view class="container">
		<view class="line"></view>
		<u-cell-group>
			<u-cell-item title="修改手机号" :value="phone" @click="handleClickChangePhone"></u-cell-item>
			<u-cell-item title="登录密码" @click="handleClickChangePW"></u-cell-item>
			<u-cell-item title="检测更新" @click="handleClickUpdate"></u-cell-item>
			<u-cell-item :arrow="false" title="清理缓存" :value="num+'MB'" :value-style="{'color':'#4B9CFF'}" @click="handleClickClear"></u-cell-item>
		</u-cell-group>
		<view class="btn" @click="handleClickLogout">
			退出登录
		</view>
		
		<view class="btn-logout" @click="WriteOffs">
			注销账号
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				popupShow: false,
				num: '16.5',
				show: false,
				content: '确定要退出吗',
				phone:this.$store.state.userInfo.phone
			}
		},
		onLoad(){
			console.log(this.$store.state.userInfo.phone);
		},
		methods: {
			handleClickUpdate(){
				this.$mRouter.push({
					route: this.$mRoutesConfig.update
				})
			},
			handleClickClear() {
				let that = this;
				uni.showLoading({
					title: '清理中'
				});
				uni.clearStorage();
				setTimeout(function() {
					uni.hideLoading();
					that.$refs.uToast.show({
						title: '清理成功',
						type: 'success',
					})
					that.num = 0;
				}, 2000);
			},
			handleClickLogout() {	
				this.logout();	
				uni.removeStorageSync('userInfo');
				this.$store.commit('WEBSOCKET_CLOSE')
				// uni.onSocketOpen(function () {
				// 	console.log('socket close ')
				//   uni.closeSocket();
				// });
				uni.closeSocket()
				uni.redirectTo({
					url: '../../login/login'
				});
									
						
			},		
			async logout(){
				let result = await this.$apis.loginOut();
				this.$store.commit('SET_USERINFO', '');
			
			},
			handleClickChangePW() {
				this.$mRouter.push({
					route: this.$mRoutesConfig.changePW
				})
			},
			handleClickChangePhone() {
				this.$mRouter.push({
					route: this.$mRoutesConfig.changePhone
				})
			},
			WriteOffs(){
				var that = this;
				uni.showModal({
					title:"提示",
					content:"您确认要注销账号吗？",
					success(res) {
						if(res.confirm){
							that.editAppUserLoginPrivilege();
						}
					}
				})
			},
			async editAppUserLoginPrivilege(){
				let {code} = await this.$apis.editAppUserLoginPrivilege({userId:this.$store.state.userInfo.id,status:0});
				if(code == 200){
					this.$refs.uToast.show({
						title: '注销成功',
						type: 'success',
					})
					this.handleClickLogout();
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		.btn {
			width: 690upx;
			margin-left: 30upx;
			height: 80upx;
			background-color: #AB61FF;
			margin-bottom: 30upx;
			border-radius: 40upx;
			text-align: center;
			line-height: 80upx;
			color: #fff;
			font-size: 32upx;
			position: absolute;
			bottom: 140upx;
		}
		.btn-logout {			
			width: 200upx;
			height: 80upx;
			margin-bottom: 30upx;
			border-radius: 40upx;
			text-align: center;
			line-height: 80upx;
			color: #AB61FF;
			font-size: 32upx;
			position: absolute;
			bottom: 30upx;
			right:30rpx;
		}
		.line {
			width: 100%;
			height: 20upx;
			background-color: #F4F4F4;
		}
	}
</style>
